import * as config from '@/config/config.js'

export function textLimitLength(val, len) {
  if (!val) {
    return ''
  }
  if (val.length <= len) {
    return val;
  }
  return val.substr(0, len - 3) + "...";
}

export function userCheckInfoImgUrl(imgPath) {
	if(!imgPath) {
		return undefined;
	}
  return config.fileBaseUrl + 'api/UserCheckInfo/' + imgPath;
}

export function userCheckInfoMinImgUrl(imgPath) {
  if (!imgPath) {
    return undefined
  }
  var suffixIndex = imgPath.lastIndexOf('.')
  return suffixIndex >= 0
    ? config.fileBaseUrl + 'api/UserCheckInfo/' + imgPath.substr(0, suffixIndex) + '_min' + imgPath.substr(suffixIndex)
    : config.fileBaseUrl + 'api/UserCheckInfo/' + imgPath;
}

export function addImageMin(imgUrl) {
	if(!imgUrl || imgUrl === "") {
		return undefined
	}
	var suffixIndex = imgUrl.lastIndexOf('.');
	if(suffixIndex < 0) {
		return imgUrl;
	}
	return imgUrl.substr(0, suffixIndex) + '_min' + imgUrl.substr(suffixIndex)
}

export function removeMin(imgUrl) {
	if(!imgUrl || imgUrl === "") {
		return undefined
	}
	var minIndex = imgUrl.lastIndexOf("_min");
	if(minIndex < 0) {
		return imgUrl;
	}
	return imgUrl.substr(0, minIndex - 1) + imgUrl.substr(minIndex + 3);
}

